#include "ringBuffer.h"
#include <stdio.h>
#include <string.h>

//缓冲区大小必须是2的幂次！！！
int main(int argc,char **argv)
{
    ringBuffer_t ringBuffer;
    uint8_t buffer[4] = {'0','0','0','0'};
    uint8_t userGetBuffer[16] = {0};
    uint8_t userPutBuffer[16] = {0};
    int flag = 0;
    ringBufferInit(&ringBuffer,buffer,sizeof(buffer));

    printf("buffer ptr:%x  userGetBuffer:%x   userPutBuffer:%x",buffer,userGetBuffer,userPutBuffer);

    while (1)
    {
        printf("输入 1：写入 2：读取\r\n");
        scanf("%d",&flag);
        if(flag == 1)
        {
            printf("请写入数据\r\n");
            scanf("%s",userGetBuffer);
            ringBufferWrite(&ringBuffer,userGetBuffer,strlen(userGetBuffer));
            userGetBuffer[0] = '\0';//几个数组的地址是连续的，所以需要把首位边侧斜杠0断掉，不然会把后面一起打印
            printf("此时缓冲区：%s  write_ptr:%d,read_ptr:%d\r\n",ringBuffer.buffer,ringBuffer.write_ptr,ringBuffer.read_ptr);
        }
        else if(flag == 2)
        {
            ringBufferRead(&ringBuffer,userPutBuffer,3);
            printf("读取到数据：%s\r\n",userPutBuffer);
            printf("此时缓冲区：%s  write_ptr:%d,read_ptr:%d\r\n",ringBuffer.buffer,ringBuffer.write_ptr,ringBuffer.read_ptr);
        }
    }

    return 0;
}